package cn.cocho.android.mct.comp.listview;

import java.util.ArrayList;
import java.util.List;

import cn.cocho.android.mct.R;
import cn.cocho.android.mc.base.Page;
import cn.cocho.android.mc.comp.listview.BaseListViewAdapter;
import cn.cocho.android.mc.comp.listview.McListView;
import cn.cocho.android.mc.storage.ApplicationCache;

import android.content.Context;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class ListViewAdapterTest extends BaseListViewAdapter<String>{

	McListView listView = null;
	public ListViewAdapterTest(McListView listView) {
		super(listView);
		this.listView = listView;
	}

	public Page<String> loadData(Page<String> page) {
		//下拉刷新的时候page.getPageNo()=1
		List<String> dataList = new ArrayList<String>();
		if(page.getTotal()<=0){
			page.setTotal(100);
		}
		for (int j = page.getStartIndex(); j < page.getEndIndex(); j++) {
			String content = "下拉刷新第" + j + "条";
			dataList.add(content);
		}
		
		try {
			Thread.sleep(3000);//为了测试时显示等待效果，正式使用时不需要
		} catch (InterruptedException e) {
		}
		
		page.setRows(dataList);
		return page;
	}


	@Override
	protected View getItemView(int position, View convertView, ViewGroup parent) {//TODO
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) ApplicationCache.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.mc_list_view_item, null);
		}
		TextView tv = (TextView) convertView.findViewById(R.id.tv);
		String content = itemList.get(position);
		tv.setText(content);
		return convertView;
	}
	
	@Override
	protected void updateMainView(Message msg) {
		
	}

}
